<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2021/4/20
  Time: 8:36 上午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>四大作用域</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>
<body>
    <%
        //jsp高级的内置对象PageContext - 获取其他对象
        //1. page作用域 - 只在当前jsp页面中生效
        //如果没有第三个参数,那么默认就是放在page作用域
        //pageContext.setAttribute("username","admin");
        pageContext.setAttribute("username","admin",1);

        //2. request作用域
        //pageContext.setAttribute("username","tom",2);
        request.setAttribute("username","tom");

        //3. session作用域
        //pageContext.setAttribute("username","jack",3);
        session.setAttribute("username","jack");

        //4. application作用域
        //pageContext.setAttribute("username","james",4);
        application.setAttribute("username","james");
    %>

<%--    EL表达式只能获取作用域中的数据的 - 推荐使用的 - 语法比较简单--%>
<%--    ${key} - 默认的肯定是从最小作用域开始向上搜索--%>
<%--    获取指定作用域中某个key对应的值 - pageScope,requestScope,sessionScope,applicationScope--%>
    ${username}<br>
    ${sessionScope.username}<br>

<%--    默认是从最小作用域开始向上搜索--%>
    <%=pageContext.getAttribute("username")%>
    <%=pageContext.getAttribute("username",4)%>

</body>
</html>
